<?php

if (isset($_POST['forum']))
{
    $data['forum'] = attribute_escape($_POST['forum']);
    $data['category'] = attribute_escape($_POST['category']);
    $data['search'] = attribute_escape($_POST['search']);
    $data['results_per_page'] = attribute_escape(intval($_POST['results_per_page'])); 
    $data['order'] = attribute_escape($_POST['order']); 
   	$data['min_temp'] = attribute_escape(intval($_POST['min_temp'])); 
   	$data['heading_text'] = attribute_escape($_POST['heading_text']); 
   
    update_option('wp-hukd', $data);
    
}

$data = get_option('wp-hukd');
?>
<? if(!$can_write_to_cache){ ?>
	<div style="color:#f00;margin-bottom:10px;">
		Cache directory is not writable please chmod <?=CACHE_PATH;?> to 0775 to enable caching.
	</div>
<? } ?>

<? if(!@hukd_test_key()){ ?>
	<div style="color:#f00;margin-bottom:10px;">
		Current API Key invalid <a href="options-general.php?page=HUKD"?>update API key</a>
	</div>
<? } ?>
<p>
	<label>Heading Text</label><br/>
	<input name="heading_text" value="<?=@$data['heading_text'];?>"/>
</p>

<p>
	<label>Forum</label><br/> 
	<select name="forum">
		<? 
		$forums=hukd_get_forums();
		foreach($forums as $name=>$id){ ?>
			<option value="<?=$id;?>" <? if($id==@$data['forum']){ ?> selected="selected" <? } ?>><?=$name;?></option>
		<? } ?>
	</select>
</p>

<p>
	<label>Category</label><br/>
	<select name="category">
  		<?
  		$categories=hukd_get_categories();
  		foreach($categories as $name=>$id){ ?>
			<option value="<?=$id;?>" <? if($id==@$data['category']){ ?> selected="selected" <? } ?>><?=$name;?></option>
		<? } ?>
 	 </select>
</p>

<p>
	<label>Search Term (optional)</label><br/>
	<input name="search" value="<?=@$data['search'];?>"/>
</p>

<p>
	<label>Number of results</label><br/>
 	<input name="results_per_page" maxlength="3" style="width:40px" value="<?=@$data['results_per_page'];?>"/>
</p>

<p>
	<label>Minimum Temp</label><br/>
 	<input name="min_temp" maxlength="3" style="width:40px" value="<?=@$data['min_temp'];?>"/>
</p>

<p>
	<label>Display Order</label><br/>
	<select name="order">
  		<?
  		$orders=hukd_get_orders();
  		foreach($orders as $name=>$id){ ?>
			<option value="<?=$id;?>" <? if($id==@$data['order']){ ?> selected="selected" <? } ?>><?=$name;?></option>
		<? } ?>
 	 </select>
</p>
